import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class ScreeningTest {
    // 初始化基础数据
    private Movie testMovie = new Movie("MOVIE001", "测试电影", "导演", "演员", "简介", 120, 8.5);
    private Screening screening = new Screening("SCREEN001", testMovie, "黄金厅", new Date(), 50.0);
    // 测试构造方法及属性赋值
    @Test
    void testConstructor() {
        assertEquals("SCREEN001", screening.getScreeningId());
        assertEquals(testMovie, screening.getMovie());
        assertEquals("黄金厅", screening.getCinemaHall());
        assertNotNull(screening.getTime());
        assertEquals(50.0, screening.getPrice());
    }
    // 测试创建影厅座位方法
    @Test
    void testCreateSeatsForHall() {
        // 测试黄金厅（case 1）
        List<List<Seat>> seats = screening.createSeatsForHall(1);
        assertEquals(8, seats.size()); // 黄金厅 rows=8
        assertEquals(10, seats.get(0).size()); // 黄金厅 cols=10
        // 测试无效影厅编号
        assertThrows(IllegalArgumentException.class, () -> screening.createSeatsForHall(6));
    }
    // 测试售票逻辑（sellTicket 方法）
    @Test
    void testSellTicket() {
        // 先创建座位
        screening.createSeatsForHall(1);
        // 尝试预订 (1,1) 座位
        boolean result = screening.sellTicket(1, 1);
        assertTrue(result);
        // 再次预订已占用座位
        boolean resultAgain = screening.sellTicket(1, 1);
        assertFalse(resultAgain);
    }
    // 测试属性 Getter/Setter 方法
    @Test
    void testGetterSetter() {
        // 测试 cinemaHall
        screening.setCinemaHall("钻石厅");
        assertEquals("钻石厅", screening.getCinemaHall());
        // 测试 time
        Date newTime = new Date();
        screening.setTime(newTime);
        assertEquals(newTime, screening.getTime());
        // 测试 price
        screening.setPrice(60.0);
        assertEquals(60.0, screening.getPrice());
    }
    // 测试辅助方法
    @Test
    void testHelperMethods() {
        // 初始状态：未售票
        assertFalse(screening.hasSoldTickets());
        assertEquals(0, screening.getSoldTicketsCount());
        // 售票后验证
        screening.createSeatsForHall(1);
        screening.sellTicket(1, 1);
    }
    // 测试 toString 方法
    @Test
    void testToString() {
        String actual = screening.toString();
        assertTrue(actual.contains("SCREEN001"));
        assertTrue(actual.contains("测试电影"));
        assertTrue(actual.contains("黄金厅"));
    }
}


